package com.budgetme.ui.activities;

import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;

import com.budgetme.R;
import com.budgetme.ui.fragments.CursorFragmentAdapter;

public abstract class Details extends AbstractActivity {
	private static final String TAG = Details.class.getName();
	
	public static final String EXTRA_FRAGMENT_CLASS = "EXTRA_FRAGMENT_CLASS";
	public static final String EXTRA_START_ID = "EXTRA_START_ID";
	
	protected ContentResolver mContentResolver;
	
	CursorFragmentAdapter mFragmentAdapter;
	ViewPager mViewPager;
	
	Cursor mCursor;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d(TAG, "onCreate");
		
		setContentView(R.layout.details);

		Bundle extras = getIntent().getExtras();
		String fragment = extras.getString(EXTRA_FRAGMENT_CLASS);
		int startId = extras.getInt(EXTRA_START_ID);
		
		mContentResolver = getContentResolver();
        mCursor = getCursor();
        
		mFragmentAdapter = new CursorFragmentAdapter(this, this.getFragmentManager(), fragment, mCursor);
        
        mViewPager = (ViewPager) findViewById(R.id.details_pager);
        mViewPager.setAdapter(mFragmentAdapter);
        
        mFragmentAdapter.setCurrent(startId, mViewPager);
        
	}
	
	protected abstract Cursor getCursor();

}
